package app.util.image
{
	import flash.geom.Point;
	
	public class StructureElement
	{
		public static const ZERO_POINT:Point = new Point(0, 0);
		
		public var row:int;
		public var col:int;
		public var marked:Array;		//Store marked point, according to XY
		public var orign:Point;
		
		public var name:String = null;
		
		public function isMarked(x:int, y:int):Boolean
		{
			for each(var p:Point in this.marked)
			{
				if(p.x == x && p.y == y)
				{
					return true;
				}
			}
			
			return false;
		}
		
		public static function createCrossSE(len:int):StructureElement
		{
			var se:StructureElement = new StructureElement();
			var points:Array = new Array();
			var modLen:int = len * 2 + 1;
			
			for(var i:int = 0; i < len; i++)
			{
				points.push(new Point(i, len));
				points.push(new Point(len, i));
				points.push(new Point(i + 1 + len, len));
				points.push(new Point(len, i + 1 + len));				
			}
			points.push(new Point(len, len));
			
			se.name = modLen + "x" + modLen + " Cross";
			se.row = modLen;
			se.col = modLen;
			se.marked = points;
			se.orign = new Point(len, len);	
				
			return se;
		}		

		public static function createSquareSE(len:int, origin:Point):StructureElement
		{
			var se:StructureElement = new StructureElement();
			var points:Array = new Array();
			for(var i:int = 0; i < len; i++)
			{
				for(var j:int = 0; j < len; j++)
				{
					points.push(new Point(i, j));
				}
			}
			
			se.name = len + "x" + len + " Square";
			se.row = len;
			se.col = len;
			se.marked = points;
			se.orign = origin;	
				
			return se;
		}
	}
}